package com.example.icongyou.bean;

import java.math.BigDecimal;
import java.time.LocalDateTime;

public class TeamAssignment {
    private Long id;
    private Long teamId;
    private Long submittedBy;
    private BigDecimal score;
    private LocalDateTime submittedAt;
    private LocalDateTime createdAt;
    private Integer isExcellent;
    private String assignmentId;
    private String assignmentFile;
    private AssignmentStatus assignmentStatus;

    public enum AssignmentStatus {
        FINISH("finish"),
        UNDONE("undone");

        private final String value;

        AssignmentStatus(String value) {
            this.value = value;
        }

        public String getValue() {
            return value;
        }

        public static AssignmentStatus fromValue(String value) {
            for (AssignmentStatus status : AssignmentStatus.values()) {
                if (status.value.equals(value)) {
                    return status;
                }
            }
            throw new IllegalArgumentException("Unknown assignment status: " + value);
        }
    }

    // 构造方法
    public TeamAssignment() {}

    public TeamAssignment(Long teamId, Long submittedBy, String assignmentId) {
        this.teamId = teamId;
        this.submittedBy = submittedBy;
        this.assignmentId = assignmentId;
        this.score = BigDecimal.ZERO;
        this.isExcellent = 0;
        this.assignmentStatus = AssignmentStatus.UNDONE;
    }

    // Getter和Setter方法
    public Long getId() { return id; }
    public void setId(Long id) { this.id = id; }

    public Long getTeamId() { return teamId; }
    public void setTeamId(Long teamId) { this.teamId = teamId; }

    public Long getSubmittedBy() { return submittedBy; }
    public void setSubmittedBy(Long submittedBy) { this.submittedBy = submittedBy; }

    public BigDecimal getScore() { return score; }
    public void setScore(BigDecimal score) { this.score = score; }

    public LocalDateTime getSubmittedAt() { return submittedAt; }
    public void setSubmittedAt(LocalDateTime submittedAt) { this.submittedAt = submittedAt; }

    public LocalDateTime getCreatedAt() { return createdAt; }
    public void setCreatedAt(LocalDateTime createdAt) { this.createdAt = createdAt; }

    public Integer getIsExcellent() { return isExcellent; }
    public void setIsExcellent(Integer isExcellent) { this.isExcellent = isExcellent; }

    public String getAssignmentId() { return assignmentId; }
    public void setAssignmentId(String assignmentId) { this.assignmentId = assignmentId; }

    public String getAssignmentFile() { return assignmentFile; }
    public void setAssignmentFile(String assignmentFile) { this.assignmentFile = assignmentFile; }

    public AssignmentStatus getAssignmentStatus() { return assignmentStatus; }
    public void setAssignmentStatus(AssignmentStatus assignmentStatus) { this.assignmentStatus = assignmentStatus; }

    // 业务方法
    public boolean isExcellent() {
        return isExcellent != null && isExcellent == 1;
    }

    public void markAsExcellent() {
        this.isExcellent = 1;
    }

    public void unmarkAsExcellent() {
        this.isExcellent = 0;
    }

    @Override
    public String toString() {
        return "TeamAssignment{" +
                "id=" + id +
                ", teamId=" + teamId +
                ", submittedBy=" + submittedBy +
                ", score=" + score +
                ", submittedAt=" + submittedAt +
                ", createdAt=" + createdAt +
                ", isExcellent=" + isExcellent +
                ", assignmentId='" + assignmentId + '\'' +
                ", assignmentFile='" + assignmentFile + '\'' +
                ", assignmentStatus=" + assignmentStatus +
                '}';
    }
}